package com.whfc.common.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @author: jiangyang
 * @version: v1.0.0
 */
public class DateV2Util {

    public static final DateTimeFormatter YYYY_MM_DD_HH_MM_SS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public static final DateTimeFormatter HH_MM_SS = DateTimeFormatter.ofPattern("HH:mm:ss");
    public static final DateTimeFormatter YYYY_MM_DD = DateTimeFormatter.ofPattern("yyyy-MM-dd");

    private DateV2Util() {
    }

    /**
     * 将字符串转换为LocalDateTime
     *
     * @param str
     * @return
     */
    public static LocalDateTime transLocalDateTime(String str) {
        return LocalDateTime.parse(str, YYYY_MM_DD_HH_MM_SS);
    }

    /**
     * 将字符串转换为LocalDate
     *
     * @param str
     * @return
     */
    public static LocalDate transLocalDate(String str) {
        return LocalDate.parse(str, YYYY_MM_DD);
    }

    /**
     * 将字符串转换为LocalTime
     *
     * @param str
     * @return
     */
    public static LocalTime transLocalTime(String str) {
        return LocalTime.parse(str, HH_MM_SS);
    }

    /**
     * 将LocalDateTime转换为字符串
     *
     * @param localDateTime
     * @return
     */
    public static String trans(LocalDateTime localDateTime) {
        return YYYY_MM_DD_HH_MM_SS.format(localDateTime);
    }

    /**
     * 将LocalDate转换为字符串
     *
     * @param localDate
     * @return
     */
    public static String trans(LocalDate localDate) {
        return YYYY_MM_DD.format(localDate);
    }

    /**
     * 将LocalTime转换为字符串
     *
     * @param localDate
     * @return
     */
    public static String trans(LocalTime localDate) {
        return HH_MM_SS.format(localDate);
    }

    /**
     * 获取当前时间
     *
     * @return
     */
    public static String nowLocalDateTime() {
        return trans(LocalDateTime.now());
    }


    public static String startTime(LocalDate date) {
        return append(trans(date), "00:00:00");
    }

    public static String startTime() {
        return startTime(LocalDate.now());
    }

    public static String endTime(LocalDate date) {
        return append(trans(date), "23:59:59");
    }

    public static String endTime() {
        return endTime(LocalDate.now());
    }

    private static String append(String prefix, String suffix) {
        return prefix + " " + suffix;
    }
}
